package arrayList1;

import java.util.*;

public class ArrayListDemo {
	public static void main(String[] args) {
		List<NewsTitle> newsTitle = new ArrayList<NewsTitle>();
		NewsTitle title1 = new NewsTitle(1, "财经", "admin");
		NewsTitle title2 = new NewsTitle(2, "娱乐", "admin");
		NewsTitle title3 = new NewsTitle(3, "民生", "admin");
		newsTitle.add(title1);
		newsTitle.add(title2);
		newsTitle.add(title3);
		// newsTitle.add("aaaaa"); 用泛型后添加类型不对就报错

		// 获取新闻标题的总数
		System.out.println("新闻标题总数量是：" + newsTitle.size());

		// 逐条打印每条新闻标题的名称
		for (int i = 0; i < newsTitle.size(); i++) {
			// NewsTitle news = (NewsTitle) newsTitle.get(i);
			NewsTitle news = newsTitle.get(i); // 用泛型后不需要再进行强制类型
			System.out.println(news.getId() + "-" + news.getNewsName() + "-" + news.getCreator());
		}

		NewsTitle news1 = newsTitle.get(1);
		System.out.println(news1.getNewsName());
		System.out.println(newsTitle.contains(title2));
		System.out.println(newsTitle.remove(title2));
		System.out.println(newsTitle.remove(0).getNewsName());

		for (int i = 0; i < newsTitle.size(); i++) {
			NewsTitle news = newsTitle.get(i);
			System.out.println(news.getId() + "-" + news.getNewsName() + "-" + news.getCreator());
		}
	}
}
